package com.google.code.mochaccino.framework.ui.components.table;
/*
 * Copyright 2012 Claude Houle claude.houle@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 *
 */
public class Row {

	/** The List of cells */
	private List<Cell> cells = new ArrayList<Cell>();

	/** The Row ID */
	private String id = null;

	/** The row's style */
	private String style = null;

	/** Is the row selected ? */
	private boolean selected = false;

	/**
	 * Constructor
	 *
	 * @param id        Row Id
	 * @param cellArray The Cell Array
	 */
	public Row( String id, boolean selected, String style, Cell... cellArray ) {
		this.id = id;
		this.selected = selected;
		this.style = style;
		if ( cellArray != null ) {
			for ( Cell c : cellArray ) {
				addCell( c );
			}
		}
	}

	/** Add a cell */
	public void addCell( Cell cell ) {
		cells.add( cell );
	}

	@Override
	public boolean equals( Object o ) {
		if ( o instanceof Row ) {
			Row opt = (Row) o;
			if ( id.equals( opt.id ) ) {
				return true;
			}
		}
		return super.equals( o );
	}

	/**
	 * Return the cells
	 *
	 * @return the cells
	 */
	public List<Cell> getCells() {
		return Collections.unmodifiableList( cells );
	}

	/** @return the id */
	public String getId() {
		return id;
	}

	/** Getter for freemarker. */
	public boolean getSelected() {
		return isSelected();
	}

	/** Set Style */
	public String getStyle() {
		return style;
	}

	@Override
	public int hashCode() {
		return id.hashCode();
	}

	/** @return the selected */
	public boolean isSelected() {
		return selected;
	}

	@Override
	public String toString() {
		return id;
	}
}